package org.tests

import java.util.List

import org.test.PriceAssessment;

class MainIdealPriceStrategy implements IdealPriceStrategy {

	@Override
	public Object getIdealPrice(Set<PriceAssessment> pricesSet) {
		//In order to keep things easy, we use a list instead of a Set object
		List<PriceAssessment> prices = pricesSet.toList()
		if (prices == null || prices.size() == 0){
			return 0
		}
		prices.sort{it.price};
		//Only if there are more than 4 prices, we execute the following logic
		if (prices.size() > 4){
			//We remove the first two (lowest)
			prices.remove(prices.first())
			prices.remove(prices.first())
			//Then we remove the last two (highest)
			prices.remove(prices.last())
			prices.remove(prices.last())
		}
		def avg = 0;
		for (priceAssessment in prices) {
			avg += priceAssessment.price;
		}
		avg = avg / prices.size();
		return (avg * 1.2);
	}

}
